package com.yanghang.controller;

import com.github.pagehelper.PageInfo;
import com.yanghang.entity.News;
import com.yanghang.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class NewsController {
    @Autowired
    private NewsService ns;
    @GetMapping("/new")
    public PageInfo<News> selectByPage(@RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "3") int pageSize){
        return ns.selectByPage(pageNum,pageSize);
    }
    @GetMapping("/news")
    public List<News> selectAll(){
        return ns.selectAll();
    }
    @PostMapping("/news")
    public void insertNews(@RequestBody News news){
       ns.insertNews(news);
    }

    @DeleteMapping("/news/{id}")
    public void deleteNews(@PathVariable("id") int id){
        ns.deleteNews(id);
    }

    @PutMapping("/news")
    public void updateNews(@RequestBody News news){
        ns.updateNews(news);
    }
}
